package com.senjoeson.teamfriends.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import com.senjoeson.teamfriends.R;
import com.senjoeson.teamfriends.adapter.FriendListAdapter;
import com.senjoeson.teamfriends.bean.Friend;
import com.senjoeson.teamfriends.bean.User;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by senjoeson on 2018/5/19.
 */

/**
 * 这个页面是搭伙好友列表显示的类
 */
public class FriendListActivity extends AppCompatActivity {
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerview;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acitivity_friendlist);
        ButterKnife.bind(this);

        //查询是否有好友
        mRecyclerview.setLayoutManager(new LinearLayoutManager(this));
        User currentUser = BmobUser.getCurrentUser(User.class);
        BmobQuery<Friend> friendBmobQuery = new BmobQuery<>();
        friendBmobQuery.addWhereEqualTo("userid", currentUser.getObjectId());
        friendBmobQuery.findObjects(new FindListener<Friend>() {
            @Override
            public void done(List<Friend> list, BmobException e) {
                FriendListAdapter friendListAdapter = new FriendListAdapter(list);
                mRecyclerview.setAdapter(friendListAdapter);
            }
        });
    }
}
